import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QFrame
from PyQt5.QtGui import QIcon, QFont, QPixmap
from PyQt5.QtCore import QDateTime, Qt


class LoginWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("河道深泓摆动智能预测软件")
        self.setGeometry(300, 300, 400, 300)

        # 顶部布局（包含时间和图片）
        top_layout = QHBoxLayout()

        # 时间显示
        self.time_label = QLabel()
        self.update_time()
        top_layout.addWidget(self.time_label)

        # 图片显示
        image_label = QLabel(self)
        pixmap = QPixmap("views/assets/header_bg.png")  # 替换为你的图片路径
        image_label.setPixmap(pixmap)
        top_layout.addWidget(image_label)

        # 主垂直布局
        vbox = QVBoxLayout()
        vbox.addLayout(top_layout)

        # 标题
        title_label = QLabel("河道深泓摆动智能预测软件")
        title_label.setFont(QFont("Arial", 16))
        vbox.addWidget(title_label)

        # 用户名和密码输入框
        hbox_username = QHBoxLayout()
        username_label = QLabel("用户名:")
        self.username_edit = QLineEdit()
        hbox_username.addWidget(username_label)
        hbox_username.addWidget(self.username_edit)

        hbox_password = QHBoxLayout()
        password_label = QLabel("登录密码:")
        self.password_edit = QLineEdit()
        self.password_edit.setEchoMode(QLineEdit.Password)
        hbox_password.addWidget(password_label)
        hbox_password.addWidget(self.password_edit)

        vbox.addLayout(hbox_username)
        vbox.addLayout(hbox_password)

        # 登录按钮
        login_button = QPushButton("登陆")
        login_button.clicked.connect(self.login)
        vbox.addWidget(login_button)

        self.setLayout(vbox)

    def update_time(self):
        current_date_time = QDateTime.currentDateTime()
        display_text = current_date_time.toString("yyyy-MM-dd hh:mm:ss")
        self.time_label.setText(display_text)
        self.time_label.setAlignment(Qt.AlignRight)
        self.time_label.setStyleSheet("font-size: 12px;")
        self.time_label.timer = self.startTimer(1000)

    def timerEvent(self, event):
        self.update_time()

    def login(self):
        username = self.username_edit.text()
        password = self.password_edit.text()
        print(f"用户名: {username}, 密码: {password}")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = LoginWindow()
    window.show()
    sys.exit(app.exec_())